package com.augurit.common.base.action;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.augurit.common.base.extmodel.ExtEditorGridResult;
import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Preparable;

/**
 * 基于 Ext 的 EditorGrid 组件来实现的 CRUD Action 类
 */
@SuppressWarnings("serial")
public abstract class ExtEditorGridSupport<T> extends ExtBaseAction implements ModelDriven<ExtEditorGridResult<T>>, Preparable {

	/**
	 * 进行增删改操作后,以redirect方式重新打开action默认页的result名.
	 */
	public static final String RELOAD = "reload";

	protected final Logger logger = LoggerFactory.getLogger(getClass());

	// 属性
	protected ExtEditorGridResult<T> result;
	
	/**
	 * Action函数,默认action函数，默认指向list函数.
	 */
	@Override
	public String execute() throws Exception {
		return SUCCESS;
	}

	// CRUD函数 //

	/**
	 * 分页获取对象列表
	 */
	public abstract String list() throws Exception;

	/**
	 * 新增对象
	 */
	public abstract String create() throws Exception;
	
	/**
	 * 更新对象
	 */
	public abstract String update() throws Exception;

	/**
	 * 删除对象
	 */
	public abstract String delete() throws Exception;
	
	/**
	 * 模型访问方法，使得模型数据自动与页面字段进行关联绑定
	 */
	public ExtEditorGridResult<T> getModel() {
		return result;
	}

	protected void prepareModel() throws Exception {
		result = new ExtEditorGridResult<T>();
	}

	public void prepare() throws Exception {
		prepareModel();
	}
}
